-
Notifications
You must be signed in to change notification settings - Fork 14.7k
[lldb][SymbolFileDWARF][NFC] Add FindFunctionDefinition helper #152733
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Factors out code to locate a definition DIE from a `FunctionCallLabel` into a helper. This will be useful for an upcoming refactor that extends `FindFunctionDefinition`. Drive-by: * adjusts some error messages in the `FunctionCallLabel` support code.
@llvm/pr-subscribers-lldb Author: Michael Buch (Michael137) ChangesFactors out code to locate a definition DIE from a Drive-by:
Full diff: https://github.com/llvm/llvm-project/pull/152733.diff 3 Files Affected:
diff --git a/lldb/source/Expression/IRExecutionUnit.cpp b/lldb/source/Expression/IRExecutionUnit.cpp
index e7a26d3c2dcf4..d557084acb745 100644
--- a/lldb/source/Expression/IRExecutionUnit.cpp
+++ b/lldb/source/Expression/IRExecutionUnit.cpp
@@ -799,7 +799,7 @@ ResolveFunctionCallLabel(const FunctionCallLabel &label,
auto sc_or_err = symbol_file->ResolveFunctionCallLabel(label);
if (!sc_or_err)
return llvm::joinErrors(
- llvm::createStringError("failed to resolve function by UID"),
+ llvm::createStringError("failed to resolve function by UID:"),
sc_or_err.takeError());
SymbolContextList sc_list;
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
index 84b3da37367c4..9958af26379b9 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -2483,6 +2483,30 @@ bool SymbolFileDWARF::ResolveFunction(const DWARFDIE &orig_die,
return false;
}
+DWARFDIE
+SymbolFileDWARF::FindFunctionDefinition(const FunctionCallLabel &label) {
+ DWARFDIE definition;
+ Module::LookupInfo info(ConstString(label.lookup_name),
+ lldb::eFunctionNameTypeFull,
+ lldb::eLanguageTypeUnknown);
+
+ m_index->GetFunctions(info, *this, {}, [&](DWARFDIE entry) {
+ if (entry.GetAttributeValueAsUnsigned(llvm::dwarf::DW_AT_declaration, 0))
+ return IterationAction::Continue;
+
+ // We don't check whether the specification DIE for this function
+ // corresponds to the declaration DIE because the declaration might be in
+ // a type-unit but the definition in the compile-unit (and it's
+ // specifcation would point to the declaration in the compile-unit). We
+ // rely on the mangled name within the module to be enough to find us the
+ // unique definition.
+ definition = entry;
+ return IterationAction::Stop;
+ });
+
+ return definition;
+}
+
llvm::Expected<SymbolContext>
SymbolFileDWARF::ResolveFunctionCallLabel(const FunctionCallLabel &label) {
std::lock_guard<std::recursive_mutex> guard(GetModuleMutex());
@@ -2495,37 +2519,19 @@ SymbolFileDWARF::ResolveFunctionCallLabel(const FunctionCallLabel &label) {
// Label was created using a declaration DIE. Need to fetch the definition
// to resolve the function call.
if (die.GetAttributeValueAsUnsigned(llvm::dwarf::DW_AT_declaration, 0)) {
- Module::LookupInfo info(ConstString(label.lookup_name),
- lldb::eFunctionNameTypeFull,
- lldb::eLanguageTypeUnknown);
-
- m_index->GetFunctions(info, *this, {}, [&](DWARFDIE entry) {
- if (entry.GetAttributeValueAsUnsigned(llvm::dwarf::DW_AT_declaration, 0))
- return IterationAction::Continue;
-
- // We don't check whether the specification DIE for this function
- // corresponds to the declaration DIE because the declaration might be in
- // a type-unit but the definition in the compile-unit (and it's
- // specifcation would point to the declaration in the compile-unit). We
- // rely on the mangled name within the module to be enough to find us the
- // unique definition.
- die = entry;
- return IterationAction::Stop;
- });
+ auto definition = FindFunctionDefinition(label);
+ if (!definition)
+ return llvm::createStringError("failed to find definition DIE");
- if (die.GetAttributeValueAsUnsigned(llvm::dwarf::DW_AT_declaration, 0))
- return llvm::createStringError(
- llvm::formatv("failed to find definition DIE for {0}", label));
+ die = std::move(definition);
}
SymbolContextList sc_list;
if (!ResolveFunction(die, /*include_inlines=*/false, sc_list))
- return llvm::createStringError(
- llvm::formatv("failed to resolve function for {0}", label));
+ return llvm::createStringError("failed to resolve function");
if (sc_list.IsEmpty())
- return llvm::createStringError(
- llvm::formatv("failed to find function for {0}", label));
+ return llvm::createStringError("failed to find function");
assert(sc_list.GetSize() == 1);
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
index 5042d919d9d42..d7db8a3c0869f 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
@@ -373,6 +373,13 @@ class SymbolFileDWARF : public SymbolFileCommon {
/// Returns the DWARFIndex for this symbol, if it exists.
DWARFIndex *getIndex() { return m_index.get(); }
+private:
+ /// Find the definition DIE for the specified \c label in this
+ /// SymbolFile.
+ ///
+ /// \returns A valid definition DIE on success.
+ DWARFDIE FindFunctionDefinition(const FunctionCallLabel &label);
+
protected:
SymbolFileDWARF(const SymbolFileDWARF &) = delete;
const SymbolFileDWARF &operator=(const SymbolFileDWARF &) = delete;
|
adrian-prantl
approved these changes
Aug 8, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Factors out code to locate a definition DIE from a
FunctionCallLabel
into a helper. This will be useful for an upcoming refactor that extendsFindFunctionDefinition
.Drive-by:
FunctionCallLabel
support code.